		//return the date color
		function returnDateBGColor(bgcolor) {
			if(bgcolor.split("#")[1] == "FFFFFF" || bgcolor.split("#")[1] == "fff" ||  bgcolor.split("#")[1] == "FFF" || bgcolor.split("#")[1] == "ffffff") {
				return "#444444";				
			}
			else {
				return bgcolor;				
			}
		}
		
		//returns optimum color for the bg
		function returnTextColor(bgcolor) {
			if(bgcolor.split("#")[1] > 0xffffff/2)
				return "#222222";		
			else
				return "#ffffff";				
			
		}
		
/*********************************************************/

//s = value
//v = id or other attrib

var buildpress;
(function($) {

var docClass = ".main-page";
var txt;

var header,footer,s1,s2,s_top,s_bottom,form1,form2;

//to export css settings
var cssSettings = new Array();
for (i=0; i <4; i++)
cssSettings[i] = new Array(3);


buildpress = {

	/* Initialize */
	init : function() {	
			//if edit
		if($("#edit_details").attr("title") == "edit_theme") {
			buildpress.edit(); //start edit
		} else {
			//if normal
			buildpress.loadAll(); //loads all default vals	
		}
		
		
	},
	
	loadAll : function() {
		
		buildpress.addEvents("buildpress_menu"); //buildpress UI
		
		buildpress.addEvents("styles_css"); //all styles from page design
		buildpress.addEvents("ChangeContentColoumns"); //changes coloumns
		buildpress.addEvents("ChangeDocSize"); //changes overall document size
		buildpress.addEvents("SidebarAccess"); //sidebar
//		buildpress.addEvents("CustomHeader"); 
		buildpress.addEvents("ChangeColorScheme");
		buildpress.addEvents("SelectFontFace"); //selects fonts for differnet headers
		buildpress.addEvents("SelectColor"); //selects color
		buildpress.addEvents("SelectSize"); //selects color	
		buildpress.addEvents("CustomColorScheme");
		
		//Get contnet via AJAX and store em in vars
		s1 = buildpress.getContent(1); //get sidebar1 data
		s2 = buildpress.getContent(2); //get sidebar2 data
		s_top = buildpress.getContent('top'); //get sidebar top
		s_bottom = buildpress.getContent('bottom'); //get sidebar ottom
		txt = buildpress.getContent('content'); //main content
		header = buildpress.getContent('header');
		footer = buildpress.getContent('footer');		
		
		//INIT * GET ALL DEFAULTS *
		$('#hd').html(header);
		$('#ft').html(footer);
		
		$(docClass).attr("id", $("#which_doc").val()); //sets up the doc id
		buildpress.ChangeContentColumns($("#splitBody-0").val(),'0'); //insert 2 coloumn as default
		
		$(".sidebar-access").each(function() {
			buildpress.addRemoveSidebar($(this).attr("checked"),$(this).val());
		});
		
		buildpress.ChangeStylesheet('header',$("#header_css").val()); //load stylesheet defined by the select
		buildpress.ChangeStylesheet('footer',$("#footer_css").val()); //load stylesheet defined by the select
		buildpress.ChangeStylesheet('content',$("#body_css").val()); //load stylesheet defined by the select
		buildpress.ChangeStylesheet('widget',$("#widget_css").val()); //load stylesheet defined by the select
		
		//get default color scheme
		buildpress.changeColorScheme($("input[name='colorscheme']:checked").attr("title"));
	},
	
	edit : function() {
		
		editRow = $("#builder");
		rowData = $("#edit_details");
		
		//which document
		which_doc = $('.which_doc', rowData).text();
		$('select[name="which_doc"] option[value='+which_doc+']', editRow).attr("selected",'selected');
		
		//which document
		splitBody = $('.splitBody-0', rowData).text();
		$('select[name="splitBody-0"] option[value='+splitBody+']', editRow).attr("selected",'selected');
		
		//color scheme
		colorscheme = $('.colorscheme', rowData).text();
		$('input[name="colorscheme"]', editRow).each(function() {
			if($(this).val() == colorscheme) {
			$(this).attr("checked",'checked'); 
			
			}
		});
		
		//SIDEBARS
		sidebar_top = $('.sidebar_top', rowData).text();
		if(sidebar_top == "1") {
			$('input[name="sidebar_top"]', editRow).attr("checked",'checked'); 
		}
		
		sidebar_bottom = $('.sidebar_bottom', rowData).text();
		if(sidebar_bottom == "1") {
			$('input[name="sidebar_bottom"]', editRow).attr("checked",'checked'); 
		}
		
		//PAGE DESIGN
		header_css = $('.header_css', rowData).text();
		$('select[name="header_css"] option[value='+header_css+']', editRow).attr("selected",'selected');
		footer_css = $('.footer_css', rowData).text();
		$('select[name="footer_css"] option[value='+footer_css+']', editRow).attr("selected",'selected');
		body_css = $('.body_css', rowData).text();
		$('select[name="body_css"] option[value='+body_css+']', editRow).attr("selected",'selected');
		widget_css = $('.widget_css', rowData).text();
		$('select[name="widget_css"] option[value='+widget_css+']', editRow).attr("selected",'selected');
		
		buildpress.loadAll(); //loads all default vals
	},
	
	exportValues : function(type) {
		form1 = $("#panel-form-1").serialize();
		form2 = $("#panel-form-2").serialize();
		form3 = $("#panel-form-3").serialize();
		form4 = $("#panel-form-4").serialize();
		
		if(type == "save")
			var a = "BP_save_builder_options";
		else if(type == "edit")
			var a = "BP_edit_builder_options";
		
		$.ajax({
			   type: "POST",
			   url: ajaxURL,
			   async: false,
			   data: {action: a, themename:themename, form1:form1, form2:form2, form3:form3, form4:form4, _ajax_save_builder_options:nonce},
			   success: function(msg){
				 	window.location.replace(BP_ADMIN_URL);
			   }
			 });		
	},
	
	changeColorScheme: function(v) {
		colors = v.split(",");
		$("html,body").css("backgroundColor",colors[0]); //html,body bg color
		
		$(".date").css({"backgroundColor":returnDateBGColor(colors[1]) ,"color":returnTextColor(returnDateBGColor(colors[1]))}); //date text
		
		$("#hd,#ft").css({"backgroundColor":colors[1], "color":returnTextColor(colors[1])});
		
		$(".widgettitle").css({"backgroundColor":colors[2], "color":returnTextColor(colors[2])});
		$("#content").css("backgroundColor",colors[3]);
		$(".main-page a").css("color",colors[4]);
		$(".main-page a:hover").css("color",colors[5]);
		
	},
	
	/*	
		function addColorCSS
		alls the color CSS
	*/
	addColorCSS : function(s,v) {
			$(".main-page "+v).css("color","#"+s);
	},
	
	/*
		function ChangeStylesheet
		changes stylesheets
	
	*/
	ChangeStylesheet : function(type,filename) {
		$('link[rel*=style][title*='+type+']').each(function(i) 
		{
			this.disabled = true;
				
			if (this.getAttribute('title') == filename) {
				this.disabled = false;
			}
		});

	},
	
	deleteColorScheme : function() {
		
	},
	
	/*	
		function addEvents
		all the various events 
	*/
	addEvents : function(s) {
		switch(s) {
		
		case 'addColorScheme':
		//ADD SCHEME
			$("#custom_color_scheme_button").click(function() {
				$("input[name='colorscheme']:checked").removeAttr("checked");
				
				$.ajax({
				   type: "POST",
				   url: ajaxURL,
				   async: false,
				   data: {action: "BP_save_color",colors: $("#custom_color_scheme_creator form").serialize(), _ajax_save_color:nonce},
				   success: function(msg){
					   $(".color_scheme_thumb:last").after(msg);
				   }
				 });

				//Add events
				buildpress.addEvents("ChangeColorScheme");
				buildpress.addEvents("deleteColorScheme");
			});	
		
		break;
		
		case 'deleteColorScheme':
			//DELETE SCHEME
			$(".delete_color_scheme").click(function() {
				var cid = $(this).parent().attr("id").split("-")[2];
				
				$.ajax({
				   type: "POST",
				   url: ajaxURL,
				   data: {action: "BP_delete_color",id: cid, _ajax_delete_color:nonce},
				   beforeSend: function() {
					 	$("#color-scheme-"+cid).animate({'backgroundColor':'#fb6c6c'},300);
			   		},
				   success: function(msg){
					    $("#color-scheme-"+cid).fadeOut( function() { $("#color-scheme-"+cid).remove() });
				   }
				 });
				//Add events
				buildpress.addEvents("ChangeColorScheme");
			});
		
		break;
		
		
		case 'CustomColorScheme':
		var colors;
		
				buildpress.addEvents("addColorScheme");
				buildpress.addEvents("deleteColorScheme");
		
			$("#custom_color_scheme_link").click(function() {
				//Add events
				
				new Boxy("#custom_color_scheme_creator", {title: "Custom Color Creator"});
				colors = $("input[name='colorscheme']:checked").attr("title");
				colors = colors.split(",");
			
			for(var i=0;i<6;i++) {
				$('#cc_'+i+' div').css('backgroundColor', colors[i]);
				$('#cc_'+i+' input').val(colors[i].split("#")[1]);
			}
				
			//COLOR FOR BG
			$('#cc_0').ColorPicker({
			color: colors[0],
			onShow: function (colpkr) {
				$(colpkr).fadeIn(100);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(100);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#cc_0 div,html,body').css('backgroundColor', '#' + hex);
				$('#cc_0 input').val(hex);
			}
			});
			
			//COLOR FOR HEADER AND DATE BG
			$('#cc_1').ColorPicker({
			color: colors[1],
			onShow: function (colpkr) {
				$(colpkr).fadeIn(100);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(100);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#cc_1 div').css('backgroundColor', '#' + hex);
				$("#hd,#ft").css({"backgroundColor":'#' + hex, "color":returnTextColor('#' + hex)});
				$(".date").css({"backgroundColor":returnDateBGColor('#' + hex) ,"color":returnTextColor(returnDateBGColor('#' + hex))});
				$('#cc_1 input').val(hex);
			}
			});
			
			//COLOR FOR WIDGET TITLE
			$('#cc_2').ColorPicker({
			color: colors[2],
			onShow: function (colpkr) {
				$(colpkr).fadeIn(100);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(100);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#cc_2 div').css('backgroundColor', '#' + hex);
				$(".widgettitle").css({"backgroundColor":'#' + hex, "color":returnTextColor('#' + hex)});
				$('#cc_2 input').val(hex);
			}
			});
			
			//COLOR FOR CONTENT
			$('#cc_3').ColorPicker({
			color: colors[3],
			onShow: function (colpkr) {
				$(colpkr).fadeIn(100);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(100);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#cc_3 div,#content').css('backgroundColor', '#' + hex);
				$('#cc_3 input').val(hex);
			}
			});
			
			//COLOR FOR CONTENT
			$('#cc_4').ColorPicker({
			color: colors[4],
			onShow: function (colpkr) {
				$(colpkr).fadeIn(100);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(100);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#cc_4 div').css('backgroundColor', '#' + hex);
				$(".main-page a").css("color",'#' + hex);
				$('#cc_4 input').val(hex);
			}
			});
			
			//COLOR FOR CONTENT
			$('#cc_5').ColorPicker({
			color: colors[5],
			onShow: function (colpkr) {
				$(colpkr).fadeIn(100);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(100);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#cc_5 div').css('backgroundColor', '#' + hex);
				$(".main-page a:hover").css("color",'#' + hex);
				$('#cc_5 input').val(hex);
			}
			});
			});
			
		break;
			
		case 'ChangeColorScheme':
		//color scheme
		$("input[name='colorscheme']").click( function () {
			buildpress.changeColorScheme($("input[name='colorscheme']:checked").attr("title"));
		});
		
		break;
		
		case 'buildpress_menu':
		
		$(".builder_button").click(function() {
			var page = $(this).attr("title");
			
			if(page == "save_buildpress") {
			if($("#edit_details").attr("title") == "edit_theme") {
				buildpress.exportValues("edit");
			} else {
				buildpress.exportValues("save");				
			}
			}
			
			if($(".panel_open").length > 0) {
				if($(".panel_open").attr("id") == page)
					$(".panel_open").removeAttr("class").hide();
				else {
					$(".panel_open").removeAttr("class").hide();
					$("#"+page).show().attr("class","panel_open");
				}
			} else if($(".panel_open").length == 0) {
				$("#"+page).show().attr("class","panel_open");
			}
		});	
		break;
		
		case 'CustomHeader':
			$("#custom_header_invoke").click(function() {
				new Boxy("#custom_header_box", {title: "Dialog"});
			});
			
			$("#buttonUpload").click(function() {
					var d = new Date();
					var t = d.getTime();
				$.ajaxFileUpload
				(
					{
						url:ajaxURL+'?action=BP_custom_header_upload&time='+t,
						secureuri:false,
						fileElementId:'file',
						dataType: 'text',
						success: function (data, status)
						{
							$("#upload_form").hide();
							$("#crop_form").show();
							$("#custom_header_box").append($(document.createElement("img")).attr({src: BP_URL+"/uploads/"+data,id:"jcrop"})).show();
							var prev = '<img src = "'+BP_URL+'/uploads/'+data+'" id="preview" />';
							$("#fname").val(data);
							$("#hd").css({background:'url("'+BP_URL+'/uploads/'+data+'")  no-repeat' });
							
							jcrop_api = $.Jcrop('#jcrop',{
								onChange: updateCoords,
								onSelect: updateCoords
							});
							jcrop_api.setOptions({
								minSize: [ $("#hd").width(),  $("#hd").height() ],
								maxSize: [ $("#hd").width(),  $("#hd").height() ]
							});

						},
						error: function (data, status, e)
						{
							alert(e);
						}
					})
			});
			
			function updateCoords(c)	{
				$('#x').val(c.x);
				$('#y').val(c.y);
				$('#w').val(c.w);
				$('#h').val(c.h);
			}
			
		$("#crop_form").click(function() {
			$.ajax({
				   type: "POST",
				   url: ajaxURL,
				   data: {action:'BP_custom_header_crop',x: $('#x').val(),y: $('#y').val(),w: $('#w').val(),h: $('#h').val(),fname:$('#fname').val(),width: $("#hd").width(), height: $("#hd").height()},
				   success: function(msg){
					   $("#hd").css({background:'url("'+BP_URL+'/uploads/'+msg+'")  no-repeat' });
				   }
				 });
		});
			
			
		break;
		
		case 'styles_css':	
			//body
			$("#body_css").change(function() {
				buildpress.ChangeStylesheet('content',$(this).val()); //changes stylesheet based on select
			});
			
			//header
			$("#header_css").change(function() {
				buildpress.ChangeStylesheet('header',$(this).val()); //changes stylesheet based on select
			});
			
			//footer
			$("#footer_css").change(function() {
				buildpress.ChangeStylesheet('footer',$(this).val()); //changes stylesheet based on select
			});
			
						//widget
			$("#widget_css").change(function() {
				buildpress.ChangeStylesheet('widget',$(this).val()); //changes stylesheet based on select
			});			
		break;
		
		//NOT USED//
		case 'ChangeSidebar':
			/* Call ChangeSidebarClass when change SIDEBAR/CONTENT position/size */
			$("#which_grid").change(function() {
				 buildpress.ChangeSidebarClass($(this).val());
			});
		break;
		
		case 'SelectFontFace':
			/* Call addFontCSS to add new font */
			$(".FontSelection").change(function() {
				 var rowID = $(this).attr('id').split("-"); //get split body select id
				 buildpress.addFontCSS($(this).val(),rowID[1]);
			});
		break;
		
		case 'SelectColor':		
		$('#ColorSelect-h1').ColorPicker({
			color: '#000000',
			onShow: function (colpkr) {
				$(colpkr).fadeIn(100);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(100);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#ColorSelect-h1 div').css('backgroundColor', '#' + hex);
				$('#ColorSelect-h1 input').val(hex);
				buildpress.addColorCSS(hex,"h1"); //add color css to all headings
			}
		});
		
		$('#ColorSelect-h2').ColorPicker({
			color: '#000000',
			onShow: function (colpkr) {
				$(colpkr).fadeIn(100);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(100);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#ColorSelect-h2 div').css('backgroundColor', '#' + hex);
				$('#ColorSelect-h2 input').val(hex);
				buildpress.addColorCSS(hex,"h2"); //add color css to all headings
			}
		});
		
		$('#ColorSelect-h3').ColorPicker({
			color: '#000000',
			onShow: function (colpkr) {
				$(colpkr).fadeIn(100);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(100);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#ColorSelect-h3 div').css('backgroundColor', '#' + hex);
				$('#ColorSelect-h3 input').val(hex);
				buildpress.addColorCSS(hex,"h3"); //add color css to all headings
			}
		});
		
		$('#ColorSelect-p').ColorPicker({
			color: '#000000',
			onShow: function (colpkr) {
				$(colpkr).fadeIn(100);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(100);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#ColorSelect-p div').css('backgroundColor', '#' + hex);
				$('#ColorSelect-p input').val(hex);
				buildpress.addColorCSS(hex,"p"); //add color css to all headings
			}
		});
	
		break;
		
		case 'SelectSize':
		//if user uses slider option
		$(".SizeSelect").click(function(e) {
			var rowID = $(this).attr("id").split("-");
			var inputID = $("#SizeSelect-"+rowID[1]);
			$("#SizeSelectSlider-"+rowID[1]).show().slider({
			change: function(event, ui) {
			  $(inputID).val(ui.value);
			  $('.ui-slider-handle').show();
			  buildpress.addFontSizeCSS($(inputID).val(),rowID[1]);			  
			},
			stop: function(event, ui) { $(this).hide(); },
			orientation: "vertical",
			range: "min",
			min: 80,
			max: 300,
			value: $(inputID).val(),
			slide: function(event, ui) {
				 $(inputID).val(ui.value);
				 buildpress.addFontSizeCSS($(inputID).val(),rowID[1]);
			}
			});
		});
		
		//if user presses enter by entering value manually
		$(".SizeSelect").change(function(e) {
			var rowID = $(this).attr("id").split("-");
			buildpress.addFontSizeCSS($("#SizeSelect-"+rowID[1]).val(),rowID[1]);
			$("#SizeSelectSlider-"+rowID[1]).hide();
										 
		});
		break;
				
		case 'ChangeDocSize':
			/* changes document size */
			$('#which_doc').change(function() {
				$(docClass).attr("id", $(this).val());
			});
		break;
		
		case 'ChangeContentColoumns':
			/* Call ChangeContentColumns to change the coloumn of page */
			$('.colvalue').change(function() {
				var rowID = $(this).attr('id').split("-"); //get split body select id
				buildpress.ChangeContentColumns($(this).val(),rowID[1]);
			});
		break;
		
		case 'SidebarAccess':
			/* add sidebars to the top or bottom */
		$(".sidebar-access").click(function() {
			if($("input:checked"))
				buildpress.addRemoveSidebar($(this).attr("checked"),$(this).val());
				
		});
		break;
		
		case 'EqualHeights':
			$(".equalsidebar").equalHeights();
		break;
		
		}
	},	
	
	/*	
		function addFontCSS
		alls the font css
	*/
	addFontCSS : function(s,v) {
		$(".main-page "+v).css("font-family",s);
	},
	
	/*	
		function addFontCSS
		alls the font css
	*/
	addFontSizeCSS : function(s,v) {
		$(".main-page "+v).css("font-size",s+"%");
	},	
	/*	
		function addRemoveSidebar
		add or remove sidebar from the top or bottom
	*/
	addRemoveSidebar : function(s,v) {
		
		if(s == false) {
			$("#"+v).remove(); // removes sidebar if they exist already
		} else {
			switch(v) { //adds sidebar top or bottom based on value
			case 'sidebartop':
			$('#bd').before(s_top);
			break;
			
			case 'sidebarbottom':
			$('#bd').after(s_bottom);
			break;
			}
		}
		
		buildpress.addColorCSS($("#colorscheme-css").children("input").val(),"css"); //add color css to all headings
	},

	/*	
		function ChangeSidebarClass
		adds YUI classes to the content div as to modify the layout
		of sidebar.	
	*/
	ChangeSidebarClass : function(s) {		
		for(i=1;i<=7;i++) {
			if($(docClass).hasClass("yui-t"+i) == true) { $(docClass).removeClass("yui-t"+i); break;  }
		} //checks for already existing class and renoves if found one.
		
		$(docClass).addClass(s); //adds sidebar class to docClass
		//after change, need to reapply colors
	},
	
	/*	
		function ContentColumnsGenerate
		changes columns in content as per request
	*/
	ChangeContentColumns : function(s,v) {
		var str = '';
		switch (s) {
                    case '1':
                        str += '<div class="yui-g"><div id="content">' + "\n";
                        str += '{0}';
                        str += '</div></div>' + "\n";
                        break;
                    case '2':
                        str += '<div class="yui-g">' + "\n";
                        str += '    <div class="yui-u first">' + "\n";
                        str += '{0}';
                        str += '    </div>' + "\n";
                        str += '    <div class="yui-u" id="sidebar1">' + "\n" + s1;
                        str += '    </div>' + "\n";
                        str += '</div>' + "\n";
                        break;
                    case '3':
                        str += '<div class="yui-ge equalsidebar">' + "\n";
						str += '<div class="yui-u first">' + "\n";
						str += '<div class="yui-gd equalsidebar">' + "\n";
                        str += '    <div class="yui-u first" id="sidebar1">' + "\n" + s1;
                        str += '    </div>' + "\n";
						str += '	<div class="yui-u"><div id="content">{0}</div></div>' + "\n";
						str += '</div></div>' + "\n";
                        str += '    <div class="yui-u" id="sidebar2">' + "\n" + s2;
                        str += '    </div>' + "\n";
                        str += '</div>' + "\n";
                        break;
                    case '4':
                        str += '<div class="yui-g">' + "\n";
                        str += '    <div class="yui-g first">' + "\n";
                        str += '        <div class="yui-u first">' + "\n";
                        str += '{0}';
                        str += '        </div>' + "\n";
                        str += '        <div class="yui-u">' + "\n";
                        str += '{0}';
                        str += '        </div>' + "\n";
                        str += '    </div>' + "\n";
                        str += '    <div class="yui-g">' + "\n";
                        str += '        <div class="yui-u first">' + "\n";
                        str += '{0}';
                        str += '        </div>' + "\n";
                        str += '        <div class="yui-u">' + "\n";
                        str += '{0}';
                        str += '        </div>' + "\n";
                        str += '    </div>' + "\n";
                        str += '</div>' + "\n";
                        break;
                    case '5':
                        str += '<div class="yui-g equalsidebar">' + "\n";
                        str += '    <div class="yui-u first"><div id="content">' + "\n";
                        str += '{0}';
                        str += '    </div></div>' + "\n";
                        str += '    <div class="yui-g">' + "\n";
                        str += '        <div class="yui-u first" id="sidebar1">' + "\n" + s1;
                        str += '        </div>' + "\n";
                        str += '        <div class="yui-u" id="sidebar2">' + "\n" + s2;
                        str += '        </div>' + "\n";
                        str += '    </div>' + "\n";
                        str += '</div>' + "\n";
                        break;
                    case '6':
                        str += '<div class="yui-g equalsidebar">' + "\n";
                        str += '    <div class="yui-g first">' + "\n";
                        str += '        <div class="yui-u first" id="sidebar1">' + "\n" + s1;
                        str += '        </div>' + "\n";
                        str += '        <div class="yui-u" id="sidebar2">' + "\n" + s2;
                        str += '        </div>' + "\n";
                        str += '    </div>' + "\n";
                        str += '    <div class="yui-u"><div id="content">' + "\n";
                        str += '{0}';
                        str += '    </div></div>' + "\n";
                        str += '</div>' + "\n";
                        break;
                    case '7':
                        str += '<div class="yui-gc equalsidebar">' + "\n";
                        str += '    <div class="yui-u first"><div id="content">' + "\n";
                        str += '{0}';
                        str += '    </div></div>' + "\n";
                        str += '    <div class="yui-u" id="sidebar1">' + "\n" + s1;
                        str += '    </div>' + "\n";
                        str += '</div>' + "\n";
                        break;
                    case '8':
                        str += '<div class="yui-gd equalsidebar">' + "\n";
                        str += '    <div class="yui-u first" id="sidebar1">' + "\n" + s1;
                        str += '    </div>' + "\n";
                        str += '    <div class="yui-u"><div id="content">' + "\n";
                        str += '{0}';
                        str += '    </div></div>' + "\n";
                        str += '</div>' + "\n";
                        break;
                    case '9':
                        str += '<div class="yui-ge equalsidebar">' + "\n";
                        str += '    <div class="yui-u first"><div id="content">' + "\n";
                        str += '{0}';
                        str += '    </div></div>' + "\n";
                        str += '    <div class="yui-u" id="sidebar1">' + "\n" + s1;
                        str += '    </div>' + "\n";
                        str += '</div>' + "\n";
                        break;
                    case '10':
                        str += '<div class="yui-gf equalsidebar">' + "\n";
                        str += '    <div class="yui-u first" id="sidebar1">' + "\n" + s1;
                        str += '    </div>' + "\n";
                        str += '    <div class="yui-u"><div id="content">' + "\n";
                        str += '{0}';
                        str += '    </div></div>' + "\n";
                        str += '</div>' + "\n";
                        break;
		}
		
		str = str.replace(/\{0\}/g, txt); //replace {0} with post
		$("#page-"+v).html(str); //dynamically changes grids inside page
		
		buildpress.addEvents('EqualHeights');
		//after change, need to reapply colors
		//buildpress.addColorCSS($("#ColorSelect-p").children("input").val(),"css"); //add color css to all headings
		buildpress.changeColorScheme($("input[name='colorscheme']:checked").attr("title"));
	},
	
	/*	
		function getContent
		gets all content via ajax and returns
		t = 1,2,top,bottom,content
	*/
	getContent: function(t) {
		var m;
		$.ajax({
			   type: "POST",
			   url: ajaxURL,
			   dataType: 'html',
			   async: false,
			   data: {action: "BP_get_content", _ajax_get_sidebar:nonce, type:t },
			   success: function(msg){
				   m = msg;
			   }
			 });
		if (m) return m;
	},
	
	/*	
		function saveCSS
		saves all css settings so it can exported
		s = h1,h2,h3
		m = font-family, color, font-size
		v = value
	*/
	saveCSS: function(s,m,v) {
		var m = buildpress.returnAttribCss(m);
		switch(s) {
			case 'h1':
			cssSettings[0][m] = v;
			break;
			case 'h2':
			cssSettings[1][m] = v;
			break;
			case 'h3':
			cssSettings[2][m] = v;
			break;
			case 'p':
			cssSettings[3][m] = v;
			break;
		}
		
	},
	
	/*	
		function returnAttribCss
		returns index of attrib
		s = font-family, color, font-size
	*/
	returnAttribCss: function(s) {
		
		switch(s) {
			case 'font-family':
			return 0;			
			break;
			
			case 'font-size':
			return 1;			
			break;
			
			case 'color':
			return 2;
			break;
			
		}
		
	},
	
	saveParam: function() {
		
		
	}
};
$(document).ready(function(){ buildpress.init(); });

})(jQuery);
